/**
 * Created by panjun7@yunzongnet.com
 */
 var voucherUseInstructionsController = null;
(function(doc, win) {

    // sui 页面就绪时间
    $(doc).on("pageInit", "#voucherUseInstructionsPage", function(e, pageId, $page,isBack,isForward) {
    	if(!voucherUseInstructionsController){
        	voucherUseInstructionsController = new VoucherUseInstructionsController();
    	}
    	
        voucherUseInstructionsController.initPage(isBack);
    });


    //返回
    $(doc).on("click","#voucherUseInstructionsPage .backBtn",function(){
        var validationResult = voucherUseInstructionsController.validateVoucherUseInstructions();
        if(validationResult.success){
            CommonUtil.injectParamObject({"voucherUseInstructions":voucherUseInstructionsController.voucherUseInstructions});
            $.router.back();
        }else{
            DialogUtil.dialogWarn(validationResult.errorMsgs[0]);
        }
       
    });

    //最多显示100个字
    $(document).on("input", ".input-wrap input", function () {
        if($(this).val().length>100){
            $this.val($this.val().substr(0,100)+"...");
        }
    });

    //序号排序
    function numSort() {
        $(".input-wrap>li").each(function (index) {
            $(this).children(".num").text(index + 1 + ".");
        });
    }

    //删除
    $(document).on("click", ".input-wrap i", function () {
        $(this).parent("li").remove();
        numSort();
        $(".btn-wrap>.btn").show();
    });
    
    //添加
    $(document).on("click", ".btn-wrap>.btn", function () {
        var parent = $(".input-wrap");
        if (parent.children("li").length < 6) {
            parent.append($('<li><span class="num"></span><input type="text" placeholder="请填写一条使用说明"><i class="zhk-list_sc"></i></li>'));
            numSort();
            if (parent.children("li").length === 6) {
                $(this).hide();
            }
        }
    });
})(document, window);

